/**
 * Copyright 2012 ibiblio
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts

// grails.config.locations = [ "classpath:${appName}-config.properties",
//                             "classpath:${appName}-config.groovy",
//                             "file:${userHome}/.grails/${appName}-config.properties",
//                             "file:${userHome}/.grails/${appName}-config.groovy"]

// if (System.properties["${appName}.config.location"]) {
//    grails.config.locations << "file:" + System.properties["${appName}.config.location"]
// }

def userDir = System.properties.getProperty('user.dir')
grails.config.locations = [ "file:/etc/terasaur/terasaur-config-defaults.groovy",
                            "file:${userDir}/conf/terasaur-config-defaults.groovy",
                            "file:/etc/terasaur/terasaur-config-logging.groovy",
                            "file:${userDir}/conf/terasaur-config-logging.groovy",
                            "file:/etc/terasaur/terasaur-config-local.groovy",
                            "file:${userDir}/conf/terasaur-config-local.groovy"
                            ]

// if(System.properties["${appName}.config.location"]) {
//    grails.config.locations << "file:" + System.properties["${appName}.config.location"]
// }

grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination
grails.mime.file.extensions = false // enables the parsing of file extensions from URLs into the request format
grails.mime.use.accept.header = false
grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
                      xml: ['text/xml', 'application/xml'],
                      text: 'text/plain',
                      js: 'text/javascript',
                      rss: 'application/rss+xml',
                      atom: 'application/atom+xml',
                      css: 'text/css',
                      csv: 'text/csv',
                      all: '*/*',
                      json: ['application/json','text/json'],
                      form: 'application/x-www-form-urlencoded',
                      multipartForm: 'multipart/form-data'
                    ]

// URL Mapping Cache Max Size, defaults to 5000
//grails.urlmapping.cache.maxsize = 1000

// What URL patterns should be processed by the resources plugin
grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*']

// The default codec used to encode data with ${}
grails.views.default.codec = "none" // none, html, base64
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"

// enable Sitemesh preprocessing of GSP pages
grails.views.gsp.sitemesh.preprocess = true

// scaffolding templates configuration
grails.scaffolding.templates.domainSuffix = 'Instance'

// Set to false to use the new Grails 1.2 JSONBuilder in the render method
grails.json.legacy.builder = false

// enabled native2ascii conversion of i18n properties files
grails.enable.native2ascii = true

// packages to include in Spring bean scanning
grails.spring.bean.packages = []

// whether to disable processing of multi part requests
grails.web.disable.multipart=false

// request parameters to mask when logging exceptions
grails.exceptionresolver.params.exclude = ['password']

// enable query caching by default
grails.hibernate.cache.queries = true

// Application URLs should start at the root
grails.app.context = "/"

// Cache lookup name/value entries
lookups.cache.size.kb = 32

// Added by the Spring Security Core plugin:
grails.plugins.springsecurity.userLookup.userDomainClassName = 'org.ibiblio.terasaur.user.User'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'org.ibiblio.terasaur.user.UserRole'
grails.plugins.springsecurity.authority.className = 'org.ibiblio.terasaur.user.Role'
grails.plugins.springsecurity.rememberMe.persistent = true
grails.plugins.springsecurity.rememberMe.persistentToken.domainClassName = 'org.ibiblio.terasaur.user.PersistentLogin'
grails.plugins.springsecurity.openid.domainClass = 'org.ibiblio.terasaur.user.OpenId'
grails.plugins.springsecurity.openid.registration.autocreate = false
grails.plugins.springsecurity.openid.registration.roleNames = []

grails.plugins.springsecurity.anon.key='terasauranonkey'
grails.plugins.springsecurity.controllerAnnotations.staticRules = [
    // order is important here.  note the last /plugins/** rule.
    '/plugins/**/js/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/plugins/**/css/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/plugins/**/images/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/plugins/**/jquery-ui/themes/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/plugins/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/grails/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/user/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/role/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/admin/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/aclclass/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/aclentry/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/aclobjectidentity/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/aclsid/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/persistentlogin/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/lookup/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/lookupvalue/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/requestmap/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/securityinfo/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/register/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/registrationcode/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/searchable/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmArchive/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    //'/wcmContent/**': view access to weceem content
    '/wcmContentSubmission/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmEditor/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmFeeds/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmPortal/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmRepository/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmSearch/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmSpace/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmSynchronization/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    '/wcmWikiItemRender/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY'],
    'openFileManagerConnector/**': ['ROLE_ADMIN', 'IS_AUTHENTICATED_FULLY']
 ]

// jquery-ui settings
grails.resources.modules = {
    overrides {
        'jquery-theme' {
            resource id:'smoothness', url:'/css/jquery-ui-1.7.3-smoothness.css'
        }
    }
}

compress {
    // just in case for some reason you want to disable the filter
    enabled = true

    debug = false
    statsEnabled = true
    compressionThreshold = 1024
    // filter's url-patterns
    urlPatterns = ["/*"]
    // include and exclude are mutually exclusive
    includePathPatterns = []
    excludePathPatterns = [".*\\.png", ".*\\.gif", ".*\\.ico", ".*\\.jpg"]
    // include and exclude are mutually exclusive
    includeContentTypes = []
    excludeContentTypes = ["application/x-bittorrent"]
    // include and exclude are mutually exclusive
    includeUserAgentPatterns = []
    excludeUserAgentPatterns = [".*MSIE 4.*"]
    // probably don't want these, but their available if needed
    javaUtilLogger = ""
    jakartaCommonsLogger = ""

    development {
        debug = true
        compressionThreshold = 2048
    }
    production {
        statsEnabled = false
    }
}

weceem {
    admin.layout = 'weceemadmin_custom'
    create.default.space = false
    content.prefix = 'pages'
    springsecurity.details.mapper = { ->
        [   username: username,
            password: password,
            enabled: enabled,
            authorities: authorities,
            email: username,
            id: id
        ]}
}
